const createVersionPolling = ({ pollingInterval = 5 * 1000, onUpdated = () => {} }) => {
  const worker = new Worker(new URL('./worker.js', import.meta.url))
  // 发送初始化配置
  worker.postMessage({
    type: 'INIT',
    payload: { pollingInterval },
  })
  // 监听 Worker 消息
  worker.onmessage = (e) => {
    if (e.data.type === 'UPDATE') {
      onUpdated()
    }
  }
  return () => worker.terminate()
}

export default createVersionPolling
